import jdk.swing.interop.SwingInterOpUtils;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-07-21
 * Time: 11:41
 */
public class Test2 {
    private static Object locker1 = new Object();

    private static Object locker2 = new Object();

    private static Object locker3 = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread A = new Thread(() -> {
            for(int i = 0; i < 10; i++) {
                System.out.print("A");
                synchronized(locker1) {
                    locker1.notify();
                }
                synchronized(locker3) {
                    try {
                        locker3.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });

        Thread B = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                synchronized(locker1) {
                    try {
                        locker1.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("B");
                }
                synchronized(locker2) {
                    locker2.notify();
                }
            }
        });

        Thread C = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                synchronized(locker2) {
                    try {
                        locker2.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("C");
                    synchronized(locker3) {
                        locker3.notify();
                    }
                }
            }
        });
        A.start();
        B.start();
        C.start();
    }
}
